/**
 * “计划”管理页面
 * - 使用自定义封装组件，简化代码，统一管理。
 * - 2025-09-06 10:08:36 tzj
 * */

import withBasePage from "../../components/BaseComponent/withBasePage";
import {jhApi} from "../../services/basic";
import EditItem from "./addOrEdit"
import React from "react";

// 要显示的form表单
const formItemList =
    [
        "fuzzy",
        // {
        //     name: "text",
        //     keywork: "jhmc",
        //     label: "计划名称"
        // },
        "jhAccounts",
        // "dateRange",
        "stateFlag2",
    ];

// 显示的按钮
const buttons = ["query", "add", "export", "edit", "delete"];
// 表格列信息
const columns = [
    {
        title: '计划id',
        dataIndex: 'jhid',
    },
    {
        title: '计划名称',
        dataIndex: 'jhmc',
    },
    {
        title: "账号名称",
        dataIndex: "zhmc",
    },
    {
        title: "状态",
        dataIndex: "ztbz",
        render(zt) {
            return !zt || zt === "0" ? "无效" : "有效"
        }
    }
]

// 加工数据
const dataProcess = res => {
    console.log("----")
    console.log(res)
    return res
}

// 实际执行还是在class里，而非视为function
const modalRef = React.createRef()

// 打开弹窗
const setHandler = (handler, record) => {
    modalRef.current.showModal(handler, record)
    console.log(handler, record)
}

export default withBasePage({
    state: {
        formItemList,
        buttons,
        // columns,
        filename: "计划管理",
        // queryAll: true,
        // sumRow: true,
        // resNormal: true,
        // rowKey: "jhid",
    },
    columns,
    queryApi: jhApi.getJh,
    dataProcess,
    setHandler,
    deleteApi: jhApi.deleteJh,
    // hasLzModal: true,
    onRowDoubleClick(record) {
        setHandler("view", record)
    },
    extraContentAfterTable: (hoc) => <EditItem editItemDone={() => hoc.queryDataList()} ref={modalRef}></EditItem>,
})(() => null);
